home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume4 / calgen / part1 next >
Encoding:
Internet Message Format  |  1986-11-30  |  38.7 KB

  1. Subject: Calendar Generation Program (1 of 2)
  2. Newsgroups: mod.sources
  3. Approved: jpn@panda.UUCP
  4.  
  5. Mod.sources:  Volume 4, Issue 108
  6. Submitted by: genrad!linus!raybed2!rayssd!dhb (David H. Brierley)
  7.  
  8. This is part one of my calendar generation program.  This
  9. file contains all of the source code and the next one contains
  10. the data file.  This program works on 4.1/4.2 BSD on a VAX and
  11. on a PYRAMID.  It has never been tested on any other systems
  12. because I don't have access to any other systems.  It should
  13. work fine fine on system III/V if you compile with -Dindex=strchr.
  14. If you have any problems porting it to other systems let me know
  15. and I will help out as much as I can.  If you make any changes
  16. to the program, either for porting purposes or otherwise, let
  17. me know and I will see about incorporating the changes into my
  18. source.  This program requires 'getopt' which is not included
  19. with this distribution.
  20.  
  21. #! /bin/sh
  22. # This is a shell archive, meaning:
  23. # 1. Remove everything above the #! /bin/sh line.
  24. # 2. Save the resulting text in a file.
  25. # 3. Execute the file with /bin/sh (not csh) to create the files:
  26. #    README
  27. #    Makefile
  28. #    calndr.c
  29. #    pic_h2m.c
  30. #    pic_m2h.c
  31. # This archive created: Thu May  8 18:09:36 1986
  32. export PATH; PATH=/bin:$PATH
  33. echo shar: extracting "'README'" '(4334 characters)'
  34. if test -f 'README'
  35. then
  36.     echo shar: will not over-write existing file "'README'"
  37. else
  38. cat << \SHAR_EOF > 'README'
  39.           Calendar Generation Program
  40.         Copyright 1986 David H. Brierley
  41.  
  42. Permission is granted to anyone to use this software for any
  43. purpose on any computer system, and to redistribute it freely,
  44. subject to the following restrictions:
  45. 1. The author is not responsible for the consequences of use of
  46.     this software, no matter how awful, even if they arise
  47.     from defects in it.
  48. 2. The origin of this software must not be misrepresented, either
  49.     by explicit claim or by omission.
  50. 3. Altered versions must be plainly marked as such, and must not
  51.     be misrepresented as being the original software.
  52.  
  53. David H. Brierley
  54. Portsmouth, RI
  55. {allegra,ihnp4,linus}!rayssd!dhb
  56.  
  57. Note:  I claim the programs as my own but disavow all
  58. knowledge of the associated data file.
  59.  
  60. PLEASE read this file all the way through before installing
  61. the program.  Installation instructions and notes are at the
  62. end of this file.
  63.  
  64.  
  65. The files in this directory are the source and data files
  66. for the calndr program.  There is no manual page but the
  67. program operation is fairly simple.  The program has the
  68. name of the default data file compiled into it so all the
  69. user normally has to do is specify what to do with the
  70. output. The program is almost completely interactive and
  71. there is a built in help facility which explains all the
  72. program inputs.  Since I have a thing against duplication
  73. of effort, run the program if you want an explantion of
  74. the input formats.
  75.  
  76. calndr.c
  77.     This is the main calendar program.  Command line
  78.     options are as follows:
  79.     -f filename    alternate data file in internal format
  80.     -r filename    alternate data file in raw format
  81.     -o filename    create calendar in named file
  82.     -P printer     send calendar to specified printer
  83.  
  84. pic_h2m.c
  85.     This program converts data files from the raw (human
  86.     readable) format to the internal format.  See the comments
  87.     in the source file for an explantion of the two formats.
  88.     In order to use the -r option of the calndr program,
  89.     this program must be installed somewhere where the calndr
  90.     program can find it.  This program takes arguments of the
  91.     input file name and the output file name.
  92.  
  93. pic_m2h.c
  94.     This program is the reverse of pic_h2m.  The main reason
  95.     for having this program is that it has a '-c' option
  96.     which produces a 'compressed' version of the raw data file.
  97.     The compress format is defined in the comments in the
  98.     source.  This program takes an optional argument of -c,
  99.     followed by the names of the input and output file names.
  100.  
  101. compress.data
  102.     This file is the compressed version of the raw data file.
  103.     This file should be transformed into internal format using
  104.     the pic_h2m program.  If you want an easily readable version
  105.     of this file you may run the pic_m2h program on the resultant
  106.     file.
  107.  
  108.  
  109.  
  110.     Installation Instructions:
  111.  
  112. 1. Decide where you want to put the default data file.
  113. 2. Edit the makefile and change the line that says 'PICDATA=' to
  114.    reflect the choice made in step 1.  You should also edit the
  115.    line that says 'GETOPT=' to define where to find the getopt
  116.    routine if it is not in your site's standard library.  This may
  117.    be a library which contains getopt, or just a .o file.
  118. [   2a. Also check the PAGER variable in the makefile.  If your site
  119.     does not have a favorite "more" like program, then set this
  120.     variable to nothing.
  121.             - moderator
  122. ]
  123. 3. type 'make'
  124. 4. There is no 'make install', simply move the executables to
  125.    wherever you want them.  If you want to allow use of the '-r'
  126.    option to the calndr program you must install the 'pic_h2m'
  127.    program, otherwise all you have to install is 'calndr'.
  128. 5. Enjoy.
  129.  
  130.  
  131.     Installation Notes:
  132.  
  133. 1.  The current version of this program has only been tested on
  134.     4.1/4.2 BSD using both a VAX and a PYRAMID although previous
  135.     versions of the program (in various languages) have been run
  136.     on 4.1(VAX), V7/PWB(PDP11/55), and OS/VS1(IBM3032).  In other
  137.     words, I know the algorithms work but I dont gaurantee that
  138.     the program is portable to other versions of UNIX (or anything
  139.     else).
  140.  
  141. 2.  The getopt routine is not included in this distribution.  If
  142.     for some strange reason you do not have getopt you can get it
  143.     from the mod.sources archive or you can probably get it from
  144.     one of your neighbors or you can get it from me.
  145. SHAR_EOF
  146. if test 4334 -ne "`wc -c < 'README'`"
  147. then
  148.     echo shar: error transmitting "'README'" '(should have been 4334 characters)'
  149. fi
  150. fi
  151. echo shar: extracting "'Makefile'" '(440 characters)'
  152. if test -f 'Makefile'
  153. then
  154.     echo shar: will not over-write existing file "'Makefile'"
  155. else
  156. cat << \SHAR_EOF > 'Makefile'
  157. PICDATA = /staff/dhb/data/picdata
  158. PAGER   = -DPAGER=\"/usr/ucb/more\"
  159. GETOPT  =
  160. CFLAGS  = -O -DPICDATA=\"$(PICDATA)\" $(PAGER)
  161. LINT    = -hbxac
  162.  
  163. all:    calndr pic_m2h pic_h2m
  164.  
  165. calndr:    calndr.o
  166.     $(CC) $(LFLAGS) calndr.o $(GETOPT)
  167.     mv a.out $@
  168.  
  169. pic_m2h:    pic_m2h.o
  170.     $(CC) $(LFLAGS) pic_m2h.o
  171.     mv a.out $@
  172.  
  173. pic_h2m:    pic_h2m.o
  174.     $(CC) $(LFLAGS) pic_h2m.o
  175.     mv a.out $@
  176.  
  177. lint:    .
  178.     lint $(LINT) calndr.c
  179.     lint $(LINT) pic_m2h.c
  180.     lint $(LINT) pic_h2m.c
  181. SHAR_EOF
  182. if test 440 -ne "`wc -c < 'Makefile'`"
  183. then
  184.     echo shar: error transmitting "'Makefile'" '(should have been 440 characters)'
  185. fi
  186. fi
  187. echo shar: extracting "'calndr.c'" '(23482 characters)'
  188. if test -f 'calndr.c'
  189. then
  190.     echo shar: will not over-write existing file "'calndr.c'"
  191. else
  192. cat << \SHAR_EOF > 'calndr.c'
  193. /*******************************************************
  194.  *
  195.  *          Calendar Generation Program
  196.  *        Copyright 1986 David H. Brierley
  197.  *
  198.  * Permission is granted to anyone to use this software for any
  199.  * purpose on any computer system, and to redistribute it freely,
  200.  * subject to the following restrictions:
  201.  * 1. The author is not responsible for the consequences of use of
  202.  *    this software, no matter how awful, even if they arise
  203.  *    from defects in it.
  204.  * 2. The origin of this software must not be misrepresented, either
  205.  *    by explicit claim or by omission.
  206.  * 3. Altered versions must be plainly marked as such, and must not
  207.  *    be misrepresented as being the original software.
  208.  *
  209.  * David H. Brierley
  210.  * Portsmouth, RI
  211.  * {allegra,ihnp4,linus}!rayssd!dhb
  212.  *
  213.  ********************************************************/
  214.  
  215. #include <stdio.h>
  216.  
  217. #define TRUE    1
  218. #define FALSE    0
  219.  
  220. #ifndef PICDATA
  221. #define PICDATA "/staff/dhb/data/picdata"
  222. #endif
  223.  
  224. struct holiday_data
  225. {
  226.     int     h_month;
  227.     int     h_day;
  228.     char    h_name[14];
  229.     struct holiday_data *h_link;
  230. };
  231. typedef struct holiday_data HDATA;
  232.  
  233. int     month1;
  234. int     year1;
  235. int     month2;
  236. int     year2;
  237. int     this_day;
  238. int     this_year;
  239. int     this_month;
  240. int     copies;
  241. int     points[13];
  242. int     days[42];
  243. int     julian_days[42];
  244. int     first;
  245. int     rawdata;
  246. int     daycnt[] =
  247. {
  248.     31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  249. };
  250. int     pic_flag;
  251. int     std_flag;
  252. int     hday_flag;
  253.  
  254. int     easter[100] =
  255. {
  256.     3, 25, 4, 13, 4, 5, 4, 18, 4, 10, 4, 1, 4, 21, 4, 6, 3, 29, 4, 17,
  257.     4, 2, 4, 22, 4, 14, 3, 29, 4, 18, 4, 10, 3, 26, 4, 14, 4, 6, 3, 29,
  258.     4, 11, 4, 2, 4, 22, 4, 14, 3, 30, 4, 18, 4, 10, 3, 26, 4, 15, 4, 6,
  259.     4, 19, 4, 11, 4, 3, 4, 22, 4, 7, 3, 30, 4, 19, 4, 3, 3, 26, 4, 15,
  260.     3, 31, 4, 19, 4, 11, 4, 3, 4, 16, 4, 7, 3, 30, 4, 12, 4, 4, 4, 23
  261. };
  262.  
  263. char    sday_file[1024];
  264. char    hday_file[1024];
  265. char    output_file[1024];
  266. char    input_file[1024];
  267.  
  268. char  **line;
  269. char   *monames[12][7];
  270. char   *nums[10][5];
  271. char   *holidays[12][32];
  272. char   *special[4][12][32];
  273.  
  274. HDATA * hday_head = NULL;
  275.  
  276. FILE   *calout;
  277.  
  278. extern  FILE   *popen ();
  279. extern  char   *index ();
  280. extern  char   *strcpy ();
  281. extern  char   *strncpy ();
  282. extern  char   *gets ();
  283. extern  char   *calloc ();
  284. extern  char   *malloc ();
  285. extern  char   *optarg;
  286. extern  int     optind;
  287.  
  288. #define alloc_3d(base, x, y, z, size) {\
  289.     register unsigned  total; register int i, j, k; register char *area;\
  290.     total = (x * y * z) * size; area = malloc (total);\
  291.     if (area == NULL) { perror ("calndr"); exit (1); }\
  292.     for (i = 0; i < x; i++) for (j = 0; j < y; j++) for (k = 0; k < z; k++) { base[i][j][k] = area; area += size; }\
  293. }
  294.  
  295. #define alloc_2d(base, x, y, size) {\
  296.     register unsigned  total; register int i, j; register char   *area;\
  297.     total = (x * y) * size; area = malloc (total);\
  298.     if (area == NULL) { perror ("calndr"); exit (1); }\
  299.     for (i = 0; i < x; i++) for (j = 0; j < y; j++) { base[i][j] = area; area += size; }\
  300. }
  301.  
  302. #define alloc_1d(base, x, size) {\
  303.     register unsigned total; register int i; register char *area;\
  304.     total = x * size; area = malloc (total);\
  305.     if (area == NULL) { perror ("calndr"); exit (1); }\
  306.     for (i = 0; i < x; i++) { base[i] = area; area += size; }\
  307. }
  308.  
  309. #define zap3(base, x, y, z) {\
  310.     register int i, j, k;\
  311.     for (i = 0; i < x; i++) for (j = 0; j < y; j++) for (k = 0; k < z; k++) *base[i][j][k] = '\0';\
  312. }
  313.  
  314. #define zap2(base, x, y) {\
  315.     register int i, j;\
  316.     for (i = 0; i < x; i++) for (j = 0; j < y; j++) *base[i][j] = '\0';\
  317. }
  318.  
  319. main (argc, argv)
  320. int     argc;
  321. char   *argv[];
  322. {
  323.     int     optch;
  324.     int     rc;
  325.  
  326.     calout = NULL;
  327.     rawdata = 0;
  328.     (void) strcpy (input_file, PICDATA);
  329.     while ((optch = getopt (argc, argv, "r:f:o:P:")) != EOF) {
  330.     switch (optch) {
  331.     case 'r':
  332.         (void) sprintf (input_file, "pic_h2m %s /tmp/picdata%d",
  333.                 optarg, getpid ());
  334.         fprintf (stderr, "Please wait while raw data file is transformed\n");
  335.         rc = system (input_file);
  336.         if (rc != 0) {
  337.         fprintf (stderr, "Unable to transform raw data file\n");
  338.         exit (1);
  339.         }
  340.         (void) sprintf (input_file, "/tmp/picdata%d", getpid ());
  341.         rawdata = 1;
  342.         break;
  343.     case 'f':
  344.         (void) strcpy (input_file, optarg);
  345.         rawdata = 0;
  346.         break;
  347.     case 'o':
  348.         calout = fopen (optarg, "w");
  349.         if (calout == NULL) {
  350.         fprintf (stderr, "Unable to open output file %s\n", optarg);
  351.         exit (1);
  352.         }
  353.         break;
  354.     case 'P':
  355.         (void) sprintf (output_file, "lpr -P%s", optarg);
  356.         calout = popen (output_file, "w");
  357.         if (calout == NULL) {
  358.         fprintf (stderr, "Unable to open pipe to printer %s\n", optarg);
  359.         exit (1);
  360.         }
  361.         break;
  362.     default:
  363.         exit (1);
  364.     }
  365.     }
  366.     if (calout == NULL) {
  367.     fprintf (stderr, "Usage: %s [-r rawdatafile] [-f datafile]\n", argv[0]);
  368.     fprintf (stderr, "       [-o outputfile] [-P printer]\n");
  369.     exit (1);
  370.     }
  371.  
  372.     alloc_2d (monames, 12, 7, 81);
  373.     alloc_2d (nums, 10, 5, 6);
  374.     alloc_2d (holidays, 12, 32, 14);
  375.     alloc_3d (special, 4, 12, 32, 17);
  376.     read_picdata ();
  377.  
  378.     while (cardscan () == TRUE) {
  379.     while (copies-- > 0) {
  380.         make_calndr ();
  381.     }
  382.     }
  383.  
  384.     if (rawdata == 1) {
  385.     (void) unlink (input_file);
  386.     }
  387.  
  388. }
  389.  
  390. make_calndr ()
  391. {
  392.     int     i;
  393.     int     j;
  394.  
  395.     this_year = year1;
  396.     this_month = month1 - 1;
  397.     daycnt[1] = 28 + leap ();
  398.     gen_hdays ();
  399.     this_day = 0;
  400.     for (i = 0; i < this_month; i++) {
  401.     this_day += daycnt[i];
  402.     }
  403.  
  404.     while (this_year < year2 || (this_year == year2 && this_month < month2)) {
  405.     this_month++;
  406.     if (this_month < 1) {
  407.         this_month = 1;
  408.     }
  409.     if (this_month > 12) {
  410.         this_month = 1;
  411.         this_year++;
  412.         this_day = 0;
  413.         daycnt[1] = 28 + leap ();
  414.         gen_hdays ();
  415.     }
  416.     if (pic_flag) {
  417.         print_picture (this_month);
  418.     }
  419.     caltop ();
  420.     first = zeller (this_month, this_year);
  421.     for (i = 0; i < 42; i++) {
  422.         days[i] = 0;
  423.         julian_days[i] = 0;
  424.     }
  425.     for (i = 0; i < daycnt[this_month - 1]; i++) {
  426.         days[i + first] = i + 1;
  427.         julian_days[i + first] = (i + 1) + this_day;
  428.     }
  429.     this_day += daycnt[this_month - 1];
  430.     dash_line (1);
  431.  
  432.     for (i = 0; i < 6; i++) {
  433.         vbar_line ();
  434.         date_line (i);
  435.         for (j = 0; j < 4; j++) {
  436.         special_line (j, this_month, i);
  437.         }
  438.         jdate_line (this_month, i);
  439.         dash_line (0);
  440.     }
  441.     }
  442. }
  443.  
  444. leap ()
  445. {
  446.     int     yr;
  447.  
  448.     yr = this_year;
  449.  
  450.     if ((yr / 4) * 4 != yr) {
  451.     return 0;
  452.     }
  453.     if ((yr / 100) * 100 != yr) {
  454.     return 1;
  455.     }
  456.     if ((yr / 400) * 400 != yr) {
  457.     return 0;
  458.     }
  459.     return 1;
  460.  
  461. }
  462.  
  463. zeller (month, year)
  464. int     month;
  465. int     year;
  466. {
  467.     int     result;
  468.     int     m,
  469.             c,
  470.             y,
  471.             f;
  472.  
  473.     y = year;
  474.     m = month - 2;
  475.     if (m <= 0) {
  476.     m += 12;
  477.     y--;
  478.     }
  479.  
  480.     c = y / 100;
  481.     y -= (c * 100);
  482.  
  483.     f = ((26 * m - 2) / 10) + 1 + ((5 * y) / 4) + (c / 4) - (2 * c);
  484.  
  485.     result = f % 7;
  486.     return result;
  487.  
  488. }
  489.  
  490. cardscan ()
  491. {
  492.     char    input_line[80];
  493.     char   *ptr;
  494.     int     plus_minus;
  495.     int     n;
  496.  
  497.     if (isatty (0)) {
  498.     printf ("Enter command line, enter '?' for help, 'q' to quit\n");
  499.     printf (">> ");
  500.     (void) fflush (stdout);
  501.     }
  502.  
  503.     if (getline (0, input_line) == -1) {
  504.     if (isatty (0)) {
  505.         printf ("\n");
  506.     }
  507.     return FALSE;
  508.     }
  509.  
  510.     if (input_line[0] == 'q') {
  511.     return FALSE;
  512.     }
  513.  
  514.     if (input_line[0] == '?') {
  515.     help ();
  516.     return cardscan ();
  517.     }
  518.  
  519.     n = sscanf (input_line, "%d/%d,%d/%d", &month1, &year1, &month2, &year2);
  520.     if (n != 4) {
  521.     printf ("Error: badly formed input line\n");
  522.     return cardscan ();
  523.     }
  524.     ptr = index (input_line, ' ');
  525.     ptr++;
  526.     zap3 (special, 4, 12, 32);
  527.     plus_minus = TRUE;
  528.     copies = 1;
  529.     pic_flag = TRUE;
  530.     std_flag = TRUE;
  531.     hday_flag = TRUE;
  532.     (void) strcpy (sday_file, "");
  533.  
  534.     while (*ptr) {
  535.     switch (*ptr) {
  536.     case '+': 
  537.         plus_minus = TRUE;
  538.         break;
  539.     case '-': 
  540.         plus_minus = FALSE;
  541.         break;
  542.     case 'p': 
  543.         pic_flag = plus_minus;
  544.         break;
  545.     case 'h': 
  546.         hday_flag = plus_minus;
  547.         if (hday_flag) {
  548.         read_holidays (ptr + 1);
  549.         }
  550.         if (hday_file[0] == '\0') {
  551.         hday_flag = FALSE;
  552.         }
  553.         ptr = index (ptr, ' ');
  554.         break;
  555.     case 's': 
  556.         std_flag = plus_minus;
  557.         break;
  558.     case 'x': 
  559.         if (plus_minus) {
  560.         read_sdays (ptr + 1);
  561.         }
  562.         ptr = index (ptr, ' ');
  563.         break;
  564.     case 'c': 
  565.         copies = atoi (ptr + 1);
  566.         if (copies < 1) {
  567.         copies = 1;
  568.         }
  569.         ptr = index (ptr, ' ');
  570.         break;
  571.     }
  572.     ptr++;
  573.     }
  574.  
  575.     printf ("options: begin = %02d/%d, end = %02d/%d, copies = %d\n",
  576.         month1, year1, month2, year2, copies);
  577.  
  578.     if (pic_flag) {
  579.     printf ("\t\tpictures");
  580.     }
  581.     else {
  582.     printf ("\t\tnopictures");
  583.     }
  584.  
  585.     if (std_flag) {
  586.     printf (", standard");
  587.     }
  588.     else {
  589.     printf (", nostandard");
  590.     }
  591.  
  592.     if (hday_flag) {
  593.     printf (", holidays(%s)", hday_file);
  594.     }
  595.     else {
  596.     printf (", noholidays");
  597.     }
  598.  
  599.     if (sday_file[0] != '\0') {
  600.     printf (", specialdays(%s)", sday_file);
  601.     }
  602.     else {
  603.     printf (", nospecialdays");
  604.     }
  605.  
  606.     printf ("\n");
  607.  
  608.     return TRUE;
  609. }
  610.  
  611. read_sdays (ptr)
  612. char   *ptr;
  613. {
  614.     char    sd_line[256];
  615.     char   *line_ptr;
  616.     char   *msg;
  617.     int     fd_sday;
  618.     int     sp_indx;
  619.     int     month;
  620.     int     day;
  621.     int     i,
  622.             j,
  623.             k,
  624.             n;
  625.  
  626.     (void) strcpy (sd_line, ptr);
  627.     msg = index (sd_line, ' ');
  628.     if (msg != NULL) {
  629.     *msg = '\0';
  630.     }
  631.     fd_sday = open (sd_line, 0);
  632.     if (fd_sday == -1) {
  633.     return;
  634.     }
  635.     (void) strcpy (sday_file, sd_line);
  636.  
  637.     while (getline (fd_sday, sd_line) != -1) {
  638.     line_ptr = sd_line;
  639.     while (*line_ptr && (*line_ptr == ' ')) {
  640.         line_ptr++;
  641.     }
  642.     if (!*line_ptr) {
  643.         continue;
  644.     }
  645.     n = sscanf (line_ptr, "%d%*c%d%*c%d", &i, &j, &k);
  646.     switch (n) {
  647.     case 3: 
  648.         if ((i < 1) || (i > 4)) {
  649.         printf ("ignoring special day line '%s'\n", sd_line);
  650.         continue;
  651.         }
  652.         if (i == 4) {
  653.         printf ("Warning: special day '%s' ", sd_line);
  654.         printf ("might be overwritten by two line holiday\n");
  655.         }
  656.         sp_indx = i - 1;
  657.         month = j - 1;
  658.         day = k;
  659.         break;
  660.     case 2: 
  661.         sp_indx = 1;
  662.         month = i - 1;
  663.         day = j;
  664.         break;
  665.     default: 
  666.         printf ("ignoring special day line '%s'\n", sd_line);
  667.         continue;
  668.     }
  669.     if (*special[sp_indx][month][day] != '\0') {
  670.         printf ("Warning: special day conflicts with previous entry\n");
  671.         printf ("currently processing file %s\n", sday_file);
  672.         printf ("input line = '%s'\n", sd_line);
  673.         printf ("previous entry = '%s'\n", special[sp_indx][month][day]);
  674.     }
  675.     msg = index (line_ptr, ' ');
  676.     while (*msg == ' ') {
  677.         msg++;
  678.     }
  679.     (void) strcpy (special[sp_indx][month][day], msg);
  680.     }
  681.     (void) close (fd_sday);
  682. }
  683.  
  684. special_line (indx, month, week)
  685. int     indx;
  686. int     month;
  687. int     week;
  688. {
  689.     int     day;
  690.  
  691.     fprintf (calout, "  ");
  692.     month--;
  693.     for (day = week * 7; day < (week + 1) * 7; day++) {
  694.     fprintf (calout, "| %-16s", special[indx][month][days[day]]);
  695.     }
  696.     fprintf (calout, "|\n");
  697. }
  698.  
  699. date_line (week)
  700. int     week;
  701. {
  702.     int     day;
  703.  
  704.     fprintf (calout, "  |");
  705.     for (day = week * 7; day < (week + 1) * 7; day++) {
  706.     if (days[day] != 0) {
  707.         fprintf (calout, "%16d |", days[day]);
  708.     }
  709.     else {
  710.         fprintf (calout, "%16s |", " ");
  711.     }
  712.     }
  713.     fprintf (calout, "\n");
  714. }
  715.  
  716. jdate_line (month, week)
  717. int     month;
  718. int     week;
  719. {
  720.     int     day;
  721.  
  722.     fprintf (calout, "  ");
  723.     month--;
  724.     for (day = week * 7; day < (week + 1) * 7; day++) {
  725.     if (days[day] != 0) {
  726.         fprintf (calout, "|%03d %-13s", julian_days[day],
  727.             holidays[month][days[day]]);
  728.     }
  729.     else {
  730.         fprintf (calout, "|%17s", " ");
  731.     }
  732.     }
  733.     fprintf (calout, "|\n");
  734. }
  735.  
  736. dash_line (n)
  737. int     n;
  738. {
  739.     while (n-- > 0) {
  740.     fprintf (calout, "\n");
  741.     }
  742.  
  743.     fprintf (calout, "  ");
  744.     for (n = 0; n < 7; n++) {
  745.     fprintf (calout, "+-----------------");
  746.     }
  747.     fprintf (calout, "+\n");
  748. }
  749.  
  750. vbar_line ()
  751. {
  752.     int     n;
  753.  
  754.     fprintf (calout, "  ");
  755.     for (n = 0; n < 7; n++) {
  756.     fprintf (calout, "%-18s", "|");
  757.     }
  758.     fprintf (calout, "|\n");
  759. }
  760.  
  761. caltop ()
  762. {
  763.     int     i;
  764.     int     y_thou;
  765.     int     y_hund;
  766.     int     y_ten;
  767.     int     y_one;
  768.  
  769.     y_thou = this_year / 1000;
  770.     y_hund = (this_year % 1000) / 100;
  771.     y_ten = (this_year % 100) / 10;
  772.     y_one = (this_year % 10);
  773.  
  774.     fprintf (calout, "\f");
  775.  
  776.     for (i = 0; i < 8; i++) {
  777.     switch (i) {
  778.     case 0: 
  779.     case 1: 
  780.         fprintf (calout, "%26s%s\n", " ", monames[this_month - 1][i]);
  781.         break;
  782.     case 2: 
  783.         fprintf (calout, "%6s%-20s%-94s%s\n", " ",
  784.             nums[y_hund][i - 2], monames[this_month - 1][i],
  785.             nums[y_ten][i - 2]);
  786.         break;
  787.     default: 
  788.         fprintf (calout, "%-6s%-20s%-94s%-6s%s\n",
  789.             nums[y_thou][i - 3], nums[y_hund][i - 2],
  790.             monames[this_month - 1][i],
  791.             nums[y_ten][i - 2], nums[y_one][i - 3]);
  792.         break;
  793.     case 7: 
  794.         fprintf (calout, "%-126s%s\n",
  795.             nums[y_thou][i - 3], nums[y_one][i - 3]);
  796.         break;
  797.     }
  798.     }
  799.     fprintf (calout, "\n%-9s%-18s%-18s%-18s%-18s%-18s%-18s%s\n",
  800.         " ", "Sunday", "Monday", "Tuesday", "Wednesday",
  801.         "Thursday", "Friday", "Saturday");
  802.  
  803. }
  804.  
  805.  
  806.  
  807. print_picture (month)
  808. int     month;
  809. {
  810.     int     i;
  811.     char   *outline;
  812.  
  813.     for (i = points[month - 1]; i < points[month]; i++) {
  814.     outline = line[i];
  815.     switch (*outline) {
  816.     case '1': 
  817.         fprintf (calout, "\f");
  818.         break;
  819.     case '-': 
  820.         fprintf (calout, "\n\n\n");
  821.         break;
  822.     case '0': 
  823.         fprintf (calout, "\n\n");
  824.         break;
  825.     case ' ': 
  826.         fprintf (calout, "\n");
  827.         break;
  828.     case '+': 
  829.         fprintf (calout, "\r");
  830.         break;
  831.     default: 
  832.         fprintf (calout, "\n");
  833.         break;
  834.     }
  835.     fprintf (calout, "%s", ++outline);
  836.     }
  837.     fprintf (calout, "\r");
  838. }
  839.  
  840. read_picdata ()
  841. {
  842.     int     picdata;
  843.     unsigned    numlines;
  844.  
  845.     picdata = open (input_file, 0);
  846.     if (picdata == -1) {
  847.     perror ("calndr");
  848.     fprintf (stderr, "Unable to open data file\n");
  849.     exit (1);
  850.     }
  851.  
  852.     if (read (picdata, monames[0][0], 12 * 7 * 81) != (12 * 7 * 81)) {
  853.     fprintf (stderr, "Incomplete read on data file while reading sss\n");
  854.     exit (1);
  855.     }
  856.     if (read (picdata, nums[0][0], 10 * 5 * 6) != (10 * 5 * 6)) {
  857.     fprintf (stderr, "Incomplete read on data file while reading sss\n");
  858.     exit (1);
  859.     }
  860.     if (read (picdata, (char *) points, sizeof points) != sizeof points) {
  861.     fprintf (stderr, "Incomplete read on data file while reading sss\n");
  862.     exit (1);
  863.     }
  864.     numlines = (unsigned) points[12];
  865.     line = (char **) calloc (numlines, sizeof (char *));
  866.     alloc_1d (line, numlines, 134);
  867.     if (read (picdata, line[0], (int) (numlines * 134)) != (numlines * 134)) {
  868.     fprintf (stderr, "Incomplete read on data file while reading sss\n");
  869.     exit (1);
  870.     }
  871.     (void) close (picdata);
  872.     return;
  873.  
  874. }
  875.  
  876. /*----- subroutine get_line                    -----*/
  877.  
  878. #define BUFFSIZE 4096
  879. #define BUFCOUNT 6
  880.  
  881. getline (fd, buf)
  882. int     fd;
  883. char   *buf;
  884. {
  885.  
  886.     static char buffer[BUFCOUNT][BUFFSIZE];
  887.     static int  buf_pos[BUFCOUNT];
  888.     static int  buf_size[BUFCOUNT];
  889.     static int  init_flag = 1;
  890.     int     i;
  891.  
  892.  
  893.     if (init_flag) {
  894.     for (i = 0; i < BUFCOUNT; i++) {
  895.         buf_pos[i] = BUFFSIZE;
  896.         buf_size[i] = BUFFSIZE;
  897.     }
  898.     init_flag = 0;
  899.     }
  900.  
  901.     if (fd >= BUFCOUNT) {
  902.     printf ("Error: get_line: fd = %d\n", fd);
  903.     exit (1);
  904.     }
  905.  
  906.  
  907.     i = 0;
  908.  
  909.     while (1) {
  910.     if (buf_pos[fd] >= buf_size[fd]) {
  911.         buf_size[fd] = read (fd, buffer[fd], BUFFSIZE);
  912.         buf_pos[fd] = 0;
  913.         if (buf_size[fd] == 0) {
  914.         break;
  915.         }
  916.     }
  917.  
  918.     if (buffer[fd][buf_pos[fd]] == '\n')
  919.         break;
  920.     if (buffer[fd][buf_pos[fd]] == 12) {
  921.         buf_pos[fd]++;
  922.         continue;
  923.     }
  924.     *buf = buffer[fd][buf_pos[fd]++];
  925.     if (*buf == '\t') {
  926.         *buf = ' ';
  927.         while (i % 8 != 7) {
  928.         *++buf = ' ';
  929.         i++;
  930.         }
  931.     }
  932.     buf++;
  933.     i++;
  934.  
  935.     }
  936.  
  937.     *buf = '\0';
  938.     if (i == 0 && buf_size[fd] == 0 && buf_pos[fd] == 0) {
  939.     i = -1;
  940.     }
  941.     buf_pos[fd]++;
  942.  
  943.     return (i);
  944.  
  945. }
  946.  
  947. #define    VU(s)    fprintf(vu, s)
  948.  
  949. help ()
  950. {
  951.     FILE   *vu;
  952.     FILE   *popen ();
  953.     char    junk[256];
  954.  
  955. #ifdef PAGER
  956.     if ((vu = popen (PAGER, "w")) == NULL)
  957. #endif
  958.     vu = stdout;
  959.  
  960.     VU ("The format of a command input line is as follows:\n");
  961.     VU (" mm/yyyy,mm/yyyy [options]\n\n");
  962.     VU ("The first mm/yyyy specifies the month and year the\n");
  963.     VU ("calendar is to begin with and the second mm/yyyy specifies\n");
  964.     VU ("the ending month and year.  The options that may be given\n");
  965.     VU ("are as follows:\n");
  966.     VU ("\n");
  967.     VU ("   +p        = print pictures\n");
  968.     VU ("   -p        = dont print pictures\n");
  969.     VU ("   +hFILE    = read list of special holidays from FILE\n");
  970.     VU ("   -h        = no special holidays\n");
  971.     VU ("   +s        = include standard holidays on calendar\n");
  972.     VU ("   -s        = dont include standard holidays\n");
  973.     VU ("   +xFILE    = read list of special days from FILE\n");
  974.     VU ("   +cNN      = print NN copies of calendar\n");
  975.     VU ("\n");
  976. #ifndef PAGER
  977.     VU ("Type RETURN for more help\n");
  978.     (void) getline (0, junk);
  979. #endif
  980.     VU ("The special day notations are written on the four lines\n");
  981.     VU ("in the center of the block for the specified day.\n");
  982.     VU ("The format of the special day entries is as follows:\n");
  983.     VU ("\n");
  984.     VU ("   n:mm/dd descriptive text\n");
  985.     VU ("\n");
  986.     VU ("The 'n:' at the beginning of the line specifies which\n");
  987.     VU ("of the four lines in the block to print the descriptive\n");
  988.     VU ("text on.  If the 'n:' is omitted, the default is to print\n");
  989.     VU ("the text on the third line.  The format of the holiday\n");
  990.     VU ("entries is the same except that the 'n:' is always omitted.\n");
  991.     VU ("The text of a holiday entry is printed on the bottom line\n");
  992.     VU ("of the block, next to the julian date.\n\n");
  993.     VU ("The descriptive text can be up to 16 characters for a\n");
  994.     VU ("special day entry and up to 13 characters for a holiday.\n");
  995.  
  996.     if (vu != stdout) {
  997.     (void) pclose (vu);
  998.     }
  999.  
  1000. }
  1001.  
  1002. gen_hdays ()
  1003. {
  1004.     HDATA * ptr;
  1005.  
  1006.     if ((this_year == year2) && (month2 == 1)) {
  1007.     return;
  1008.     }
  1009.  
  1010.     zap2 (holidays, 12, 32);
  1011.  
  1012.     if (std_flag) {
  1013.     std_hdays ();
  1014.     }
  1015.  
  1016.     if (!hday_flag) {
  1017.     return;
  1018.     }
  1019.     if (hday_head == NULL) {
  1020.     return;
  1021.     }
  1022.  
  1023.     ptr = hday_head;
  1024.     while (ptr) {
  1025.     if (*holidays[ptr -> h_month][ptr -> h_day] != '\0') {
  1026.         printf ("User specified holiday conflicts with standard holiday\n");
  1027.         printf ("\tstandard holiday = '%s', user holiday = '%s'\n",
  1028.             holidays[ptr -> h_month][ptr -> h_day], ptr -> h_name);
  1029.         (void) fflush (stdout);
  1030.     }
  1031.     (void) strcpy (holidays[ptr -> h_month][ptr -> h_day], ptr -> h_name);
  1032.     ptr = ptr -> h_link;
  1033.     }
  1034.  
  1035. }
  1036.  
  1037. std_hdays ()
  1038. {
  1039.     int     temp;
  1040.     int     month;
  1041.  
  1042.     /* fixed holidays */
  1043.     (void) strcpy (holidays[0][1], "New Years Day");
  1044.     (void) strcpy (special[3][0][15], "   Martin Luther");
  1045.     (void) strcpy (holidays[0][15], " King Jr. Day");
  1046.     (void) strcpy (holidays[1][2], "Groundhog Day");
  1047.     (void) strcpy (holidays[1][14], "Valentine Day");
  1048.     (void) strcpy (special[3][1][12], "       Lincoln's");
  1049.     (void) strcpy (holidays[1][12], "    Birthday ");
  1050.     (void) strcpy (special[3][1][22], "    Washington's");
  1051.     (void) strcpy (holidays[1][22], "   Birthday  ");
  1052.     (void) strcpy (special[3][2][17], " Saint Patrick's");
  1053.     (void) strcpy (holidays[2][17], "    Day      ");
  1054.     (void) strcpy (holidays[5][14], "Flag Day     ");
  1055.     (void) strcpy (special[3][6][4], "     Independence");
  1056.     (void) strcpy (holidays[6][4], "      Day    ");
  1057.     (void) strcpy (special[3][9][24], "  United Nations");
  1058.     (void) strcpy (holidays[9][24], "    Day      ");
  1059.     (void) strcpy (holidays[9][31], "Halloween    ");
  1060.     (void) strcpy (holidays[10][11], "Veterans Day ");
  1061.     (void) strcpy (holidays[11][25], "Christmas    ");
  1062.  
  1063.     /* Armed Forces Day */
  1064.     temp = 21 - zeller (5, this_year);
  1065.     (void) strcpy (special[3][4][temp], "    Armed Forces");
  1066.     (void) strcpy (holidays[4][temp], "     Day     ");
  1067.  
  1068.     /* Labor Day */
  1069.     temp = 9 - zeller (9, this_year);
  1070.     if (temp > 7) {
  1071.     temp -= 7;
  1072.     }
  1073.     (void) strcpy (holidays[8][temp], "Labor Day");
  1074.  
  1075.     /* Thanksgiving */
  1076.     temp = 26 - zeller (11, this_year);
  1077.     if (temp < 22) {
  1078.     temp += 7;
  1079.     }
  1080.     (void) strcpy (holidays[10][temp], "Thanksgiving");
  1081.  
  1082.     /* Memorial Day */
  1083.     temp = 30 - zeller (5, this_year);
  1084.     if (temp < 25) {
  1085.     temp += 7;
  1086.     }
  1087.     (void) strcpy (holidays[4][temp], "Memorial Day");
  1088.  
  1089.     /* Mothers Day */
  1090.     temp = 15 - zeller (5, this_year);
  1091.     if (temp > 14) {
  1092.     temp -= 7;
  1093.     }
  1094.     (void) strcpy (holidays[4][temp], "Mother's Day");
  1095.  
  1096.     /* Fathers Day */
  1097.     temp = 22 - zeller (6, this_year);
  1098.     if (temp > 21) {
  1099.     temp -= 7;
  1100.     }
  1101.     (void) strcpy (holidays[5][temp], "Father's Day");
  1102.  
  1103.     /* Columbus Day */
  1104.     temp = 16 - zeller (10, this_year);
  1105.     if (temp > 12) {
  1106.     temp -= 7;
  1107.     }
  1108.     (void) strcpy (holidays[9][temp], "Columbus Day");
  1109.  
  1110.     /* generate a couple of Canadian holidays */
  1111.     temp = 23 - zeller (5, this_year);
  1112.     (void) strcpy (special[3][4][temp], "     Canadian   ");
  1113.     (void) strcpy (holidays[4][temp], "Victoria Day ");
  1114.  
  1115.     temp = zeller (7, this_year);
  1116.     switch (temp) {
  1117.     case 0: 
  1118.     temp = 2;
  1119.     break;
  1120.     case 6: 
  1121.     temp = 3;
  1122.     break;
  1123.     default: 
  1124.     temp = 1;
  1125.     break;
  1126.     }
  1127.     (void) strcpy (special[3][6][temp], "     Canadian   ");
  1128.     (void) strcpy (holidays[6][temp], "Dominion Day ");
  1129.  
  1130.     /* if year is withing range, generate easter etc. */
  1131.     temp = this_year - 1950;
  1132.     if ((temp < 1) || (temp > 50)) {
  1133.     printf ("Warning: requested year is not within the bounds for\n");
  1134.     printf ("generating Easter and related holidays.\n");
  1135.     return;
  1136.     }
  1137.  
  1138.     temp--;
  1139.     temp *= 2;
  1140.     month = easter[temp];
  1141.     temp = easter[++temp];
  1142.     (void) strcpy (holidays[--month][temp], "Easter");
  1143.  
  1144.     temp -= 2;
  1145.     if (temp < 1) {
  1146.     month--;
  1147.     temp += daycnt[month];
  1148.     }
  1149.     (void) strcpy (holidays[month][temp], "Good Friday");
  1150.  
  1151.     temp -= 5;
  1152.     if (temp < 1) {
  1153.     month--;
  1154.     temp += daycnt[month];
  1155.     }
  1156.     (void) strcpy (holidays[month][temp], "Palm Sunday");
  1157.  
  1158.     temp -= 39;
  1159.     while (temp < 1) {
  1160.     month--;
  1161.     temp += daycnt[month];
  1162.     }
  1163.     (void) strcpy (holidays[month][temp], "Ash Wednesday");
  1164.  
  1165. }
  1166.  
  1167. read_holidays (sptr)
  1168. char   *sptr;
  1169. {
  1170.     char    file[1024];
  1171.     char    input_line[80];
  1172.     char   *temp;
  1173.     int     fd;
  1174.     int     i,
  1175.             j,
  1176.             n;
  1177.     HDATA  *ptr;
  1178.     HDATA  *next;
  1179.  
  1180.     if (*sptr == ' ') {
  1181.     return;
  1182.     }
  1183.  
  1184.     if (hday_head != NULL) {
  1185.     ptr = hday_head;
  1186.     while (ptr) {
  1187.         next = ptr -> h_link;
  1188.         free ((char *) ptr);
  1189.         ptr = next;
  1190.     }
  1191.     }
  1192.  
  1193.     hday_head = NULL;
  1194.     (void) strcpy (hday_file, "");
  1195.     (void) strcpy (file, sptr);
  1196.     if ((temp = index (file, ' ')) != NULL) {
  1197.     *temp = '\0';
  1198.     }
  1199.  
  1200.     if ((fd = open (file, 0)) == -1) {
  1201.     printf ("** warning ** - unable to open file %s\n", file);
  1202.     printf ("                +h option ignored\n");
  1203.     hday_flag = FALSE;
  1204.     return;
  1205.     }
  1206.     (void) strcpy (hday_file, file);
  1207.  
  1208.     while (getline (fd, input_line) != -1) {
  1209.     temp = input_line;
  1210.     while (*temp && (*temp == ' ')) {
  1211.         temp++;
  1212.     }
  1213.     if (!*temp) {
  1214.         continue;
  1215.     }
  1216.     n = sscanf (temp, "%d%*c%d", &i, &j);
  1217.     if (n != 2) {
  1218.         continue;
  1219.     }
  1220.     next = (HDATA *) malloc (sizeof (HDATA));
  1221.     if (next == NULL) {
  1222.         perror ("calndr");
  1223.         printf ("Unable to alocate space for holiday_data\n");
  1224.         return;
  1225.     }
  1226.     if (hday_head == NULL) {
  1227.         hday_head = next;
  1228.     }
  1229.     else {
  1230.         ptr -> h_link = next;
  1231.     }
  1232.     ptr = next;
  1233.     ptr -> h_link = NULL;
  1234.     i--;
  1235.     temp = index (temp, ' ');
  1236.     while (*temp && (*temp == ' ')) {
  1237.         temp++;
  1238.     }
  1239.     ptr -> h_month = i;
  1240.     ptr -> h_day = j;
  1241.     (void) strncpy (ptr -> h_name, temp, 13);
  1242.     }
  1243.  
  1244.     (void) close (fd);
  1245.  
  1246. }
  1247. SHAR_EOF
  1248. if test 23482 -ne "`wc -c < 'calndr.c'`"
  1249. then
  1250.     echo shar: error transmitting "'calndr.c'" '(should have been 23482 characters)'
  1251. fi
  1252. fi
  1253. echo shar: extracting "'pic_h2m.c'" '(5756 characters)'
  1254. if test -f 'pic_h2m.c'
  1255. then
  1256.     echo shar: will not over-write existing file "'pic_h2m.c'"
  1257. else
  1258. cat << \SHAR_EOF > 'pic_h2m.c'
  1259. /*******************************************************
  1260.  *
  1261.  *          Calendar Generation Program
  1262.  *        Copyright 1986 David H. Brierley
  1263.  *
  1264.  * Permission is granted to anyone to use this software for any
  1265.  * purpose on any computer system, and to redistribute it freely,
  1266.  * subject to the following restrictions:
  1267.  * 1. The author is not responsible for the consequences of use of
  1268.  *    this software, no matter how awful, even if they arise
  1269.  *    from defects in it.
  1270.  * 2. The origin of this software must not be misrepresented, either
  1271.  *    by explicit claim or by omission.
  1272.  * 3. Altered versions must be plainly marked as such, and must not
  1273.  *    be misrepresented as being the original software.
  1274.  *
  1275.  * David H. Brierley
  1276.  * Portsmouth, RI
  1277.  * {allegra,ihnp4,linus}!rayssd!dhb
  1278.  *
  1279.  ********************************************************/
  1280.  
  1281. /*
  1282.  * pic_h2m - calndr program support module
  1283.  *
  1284.  * This program converts the picture data file from human readable
  1285.  * format to the internal machine format that the calndr program
  1286.  * is expecting to see.  The purpose for doing this is to speed up
  1287.  * execution of the calndr program.  If you are concerned about the
  1288.  * extra disk space required by the internal format of the data file
  1289.  * you may use the '-r' flag to the calndr program.
  1290.  */
  1291.  
  1292. /*
  1293.  * Format of human readable version of the data file.
  1294.  * 1. The first 84 lines of the file contain the names of the months.
  1295.  *    Each month name is 7 lines long and should be centered in
  1296.  *    eighty columns.  You should probably not touch this data.
  1297.  * 2. The next 50 lines contain the numbers from 0 to 9, five lines
  1298.  *    each, five characters wide.  Again, dont touch.
  1299.  * 3. The last section of the file contains the pictures.  This section
  1300.  *    may be modified to give different pictures.  Since the original
  1301.  *    program was in FORTRAN, the picture data uses fortran carriage
  1302.  *    control characters in the first column.  The beginning of each
  1303.  *    months picture is denoted by a top of form control ("1").  There
  1304.  *    should be exactly twelve pictures.  The first picture is always
  1305.  *    used for January, the second for February, etc.  As a general
  1306.  *    rule, the picture data is straight ascii text.  The one exception
  1307.  *    to this is that a character may be followed by a count enclosed
  1308.  *    within squares brackets.  The purpose of this is to allow the
  1309.  *    data file to be compressed but still be, for the most part, human
  1310.  *    readable.  One implication of this is that the data file cannot
  1311.  *    contain an open bracket followed by a string of digits followed
  1312.  *    by a close bracket.  The current data file does not even contain
  1313.  *    any open brackets, never mind all the rest of the crap.
  1314.  */
  1315.  
  1316. #include <stdio.h>
  1317. #include <ctype.h>
  1318.  
  1319. main (argc, argv)
  1320. int     argc;
  1321. char   *argv[];
  1322. {
  1323.     char    line[140];
  1324.     char    enil[140];
  1325.     char   *p1;
  1326.     char   *p2;
  1327.     char   *p3;
  1328.     char    moname[85];
  1329.     char    nums[10];
  1330.     int     points[13];
  1331.     int     psize;
  1332.     FILE   *picdata;
  1333.     int     newdata;
  1334.     int     n;
  1335.     int     len;
  1336.     int     locator;
  1337.     long    pos;
  1338.     long    lseek ();
  1339.  
  1340.     if (argc != 3) {
  1341.     fprintf (stderr, "Usage: %s infile outfile\n", argv[0]);
  1342.     exit (1);
  1343.     }
  1344.     picdata = fopen (argv[1], "r");
  1345.     if (picdata == NULL) {
  1346.     perror ("calndr");
  1347.     fprintf (stderr, "Unable to open file '%s'\n", argv[1]);
  1348.     exit (1);
  1349.     }
  1350.     newdata = creat (argv[2], 0666);
  1351.     if (newdata == -1) {
  1352.     perror ("calndr");
  1353.     fprintf (stderr, "Unable to open file '%s'\n", argv[2]);
  1354.     }
  1355.  
  1356.     for (n = 0; n < 12 * 7; n++) {
  1357.     if (fgets (moname, 85, picdata) == NULL) {
  1358.         fprintf (stderr, "I/O error on file\n");
  1359.         exit (1);
  1360.     }
  1361.     len = strlen (moname);
  1362.     for (--len; len < 81; len++) {
  1363.         moname[len] = '\0';
  1364.     }
  1365.     if (write (newdata, moname, 81) != 81) {
  1366.         perror ("calndr");
  1367.         fprintf (stderr, "I/O error writing output file\n");
  1368.         exit (1);
  1369.     }
  1370.     }
  1371.     for (n = 0; n < 10 * 5; n++) {
  1372.     if (fgets (nums, 10, picdata) == NULL) {
  1373.         fprintf (stderr, "I/O error on file\n");
  1374.         exit (1);
  1375.     }
  1376.     len = strlen (nums);
  1377.     for (--len; len < 6; len++) {
  1378.         nums[len] = '\0';
  1379.     }
  1380.     if (write (newdata, nums, 6) != 6) {
  1381.         perror ("calndr");
  1382.         fprintf (stderr, "I/O error writing output file\n");
  1383.         exit (1);
  1384.     }
  1385.     }
  1386.     pos = lseek (newdata, 0L, 1);
  1387.     if (pos == -1) {
  1388.     perror ("calndr");
  1389.     fprintf (stderr, "Unable to determine position in file\n");
  1390.     exit (1);
  1391.     }
  1392.     psize = 13 * sizeof (int);
  1393.     if (write (newdata, (char *) points, psize) != psize) {
  1394.     perror ("calndr");
  1395.     fprintf (stderr, "I/O error writing output file\n");
  1396.     exit (1);
  1397.     }
  1398.     locator = 0;
  1399.     for (n = 0;; n++) {
  1400.     if (fgets (enil, 140, picdata) == NULL) {
  1401.         break;
  1402.     }
  1403.     if (enil[0] == '1') {
  1404.         if (locator == 12) {
  1405.         break; /* already have 12 pictures */
  1406.         }
  1407.         points[locator] = n;
  1408.         locator++;
  1409.     }
  1410.     p1 = enil;
  1411.     p2 = line;
  1412.     while (*p1 != '\n') {
  1413.         if (*p1 != '[') {
  1414.         *p2++ = *p1++;
  1415.         continue;
  1416.         }
  1417.             for (p3 = p1 + 1; isdigit (*p3); p3++) ; /* find close bracket */
  1418.         if (*p3 == ']') {
  1419.         p3 = p1 - 1;
  1420.         len = atoi (++p1);
  1421.         while (len-- > 0) {
  1422.             *p2++ = *p3;
  1423.         }
  1424.         while (*p1 != ']') p1++;
  1425.         p1++;
  1426.         continue;
  1427.         }
  1428.         *p2++ = *p1++;
  1429.     }
  1430.     for (; p2 < line + 134; p2++) {
  1431.         *p2 = '\0';
  1432.     }
  1433.     if (write (newdata, line, 134) != 134) {
  1434.         perror ("calndr");
  1435.         fprintf (stderr, "I/O error writing output file\n");
  1436.         exit (1);
  1437.     }
  1438.     }
  1439.     points[locator] = n;
  1440.     if (lseek (newdata, pos, 0) == -1) {
  1441.     perror ("calndr");
  1442.     fprintf (stderr, "Unable to seek backwards in file\n");
  1443.     exit (1);
  1444.     }
  1445.     if (write (newdata, (char *) points, psize) != psize) {
  1446.     perror ("calndr");
  1447.     fprintf (stderr, "I/O error writing output file\n");
  1448.     exit (1);
  1449.     }
  1450.  
  1451.     (void) fclose (picdata);
  1452.     (void) close (newdata);
  1453.  
  1454. }
  1455. SHAR_EOF
  1456. if test 5756 -ne "`wc -c < 'pic_h2m.c'`"
  1457. then
  1458.     echo shar: error transmitting "'pic_h2m.c'" '(should have been 5756 characters)'
  1459. fi
  1460. fi
  1461. echo shar: extracting "'pic_m2h.c'" '(2750 characters)'
  1462. if test -f 'pic_m2h.c'
  1463. then
  1464.     echo shar: will not over-write existing file "'pic_m2h.c'"
  1465. else
  1466. cat << \SHAR_EOF > 'pic_m2h.c'
  1467. /*******************************************************
  1468.  *
  1469.  *          Calendar Generation Program
  1470.  *        Copyright 1986 David H. Brierley
  1471.  *
  1472.  * Permission is granted to anyone to use this software for any
  1473.  * purpose on any computer system, and to redistribute it freely,
  1474.  * subject to the following restrictions:
  1475.  * 1. The author is not responsible for the consequences of use of
  1476.  *    this software, no matter how awful, even if they arise
  1477.  *    from defects in it.
  1478.  * 2. The origin of this software must not be misrepresented, either
  1479.  *    by explicit claim or by omission.
  1480.  * 3. Altered versions must be plainly marked as such, and must not
  1481.  *    be misrepresented as being the original software.
  1482.  *
  1483.  * David H. Brierley
  1484.  * Portsmouth, RI
  1485.  * {allegra,ihnp4,linus}!rayssd!dhb
  1486.  *
  1487.  ********************************************************/
  1488.  
  1489. /*
  1490.  * pic_m2h - calndr program support module
  1491.  *
  1492.  * This module takes the internal machine format data file and
  1493.  * converts it to human readable format.  Carriage returns are
  1494.  * added to each line (actually \n) and the picture data is
  1495.  * optionally transformed into the compressed format defined
  1496.  * by the pic_h2m program.
  1497.  *
  1498.  */
  1499.  
  1500. #include <stdio.h>
  1501.  
  1502. main (argc, argv)
  1503. int     argc;
  1504. char   *argv[];
  1505. {
  1506.     char    line[134];
  1507.     char   *p1;
  1508.     char    moname[81];
  1509.     char    nums[6];
  1510.     int     points[13];
  1511.     int     picdata;
  1512.     int     compress;
  1513.     int     count;
  1514.     int     n;
  1515.  
  1516.     compress = 0;
  1517.     picdata = -1;
  1518.     for (n = 1; n < argc; n++) {
  1519.     if (strcmp (argv[n], "-c") == 0) {
  1520.         compress = 1;
  1521.         continue;
  1522.     }
  1523.     picdata = open (argv[n], 0);
  1524.     if (picdata == -1) {
  1525.         perror ("calndr");
  1526.         fprintf (stderr, "Unable to open file '%s'\n", argv[n]);
  1527.         exit (1);
  1528.     }
  1529.     }
  1530.     if (picdata == -1) {
  1531.     fprintf (stderr, "No input file specified\n");
  1532.     exit (1);
  1533.     }
  1534.  
  1535.     for (n = 0; n < 12 * 7; n++) {
  1536.     if (read (picdata, moname, 81) != 81) {
  1537.         fprintf (stderr, "I/O error on file\n");
  1538.         exit (1);
  1539.     }
  1540.     printf ("%s\n", moname);
  1541.     }
  1542.     for (n = 0; n < 10 * 5; n++) {
  1543.     if (read (picdata, nums, 6) != 6) {
  1544.         fprintf (stderr, "I/O error on file\n");
  1545.         exit (1);
  1546.     }
  1547.     printf ("%s\n", nums);
  1548.     }
  1549.     if (read (picdata, (char *) points, sizeof points) != sizeof points) {
  1550.     fprintf (stderr, "I/O errron file\n");
  1551.     exit (1);
  1552.     }
  1553.     for (n = 0; ; n++) {
  1554.     if (read (picdata, line, 134) != 134) {
  1555.         break;
  1556.     }
  1557.     for (p1 = line; *p1 != '\0'; p1++) {
  1558.         printf ("%c", *p1);
  1559.         if (compress == 1) {
  1560.         if (*(p1 + 1) != *p1) continue;
  1561.         for (count = 1; *(p1 + count) == *p1; count++) ;
  1562.         count--;
  1563.         p1 += count;
  1564.         if (count > 5) {
  1565.             printf ("[%d]", count);
  1566.         }
  1567.         else {
  1568.             while (count-- > 0) {
  1569.             printf ("%c", *p1);
  1570.             }
  1571.         }
  1572.         }
  1573.     }
  1574.     printf ("\n");
  1575.     }
  1576.  
  1577.     (void) close (picdata);
  1578.  
  1579. }
  1580. SHAR_EOF
  1581. if test 2750 -ne "`wc -c < 'pic_m2h.c'`"
  1582. then
  1583.     echo shar: error transmitting "'pic_m2h.c'" '(should have been 2750 characters)'
  1584. fi
  1585. fi
  1586. exit 0
  1587. #    End of shell archive
  1588.